<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片上传</title>
<script type="text/javascript">

//加载相册列表
function LoadAlbumList()
{
	 var oReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
      oReq.open("POST", "add_photo.php?action=GetAlbumList", false);
      oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 // var para="albumName="+albumName;
      oReq.send(null); 
	
	  //alert(oReq.responseText);
	  eval("albumList="+oReq.responseText);
	  var txtAlbumList=document.getElementById("txtAlbumList");
	  while(txtAlbumList.lastChild!=null)
	  {
		  txtAlbumList.removeChild(txtAlbumList.lastChild);
	  }
	   
	  //动态加载相册列表
	  for(var i=0;i<albumList.length;i++)
	  {
		  var option=document.createElement("option");
		  option.innerText=albumList[i].name;
		  option.value=albumList[i].id;
		  txtAlbumList.appendChild(option);  		  
	  }
}

//添加相册
function AddAlbum()
{
	var albumName=document.getElementById('txtAlbumName').value;
	if(albumName==""||albumName==null)
	{
		alert("相册名为空！");
	}
	else
	{
	  var oReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
      oReq.open("POST", "add_photo.php?action=addAlbum", false);
      oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  var para="albumName="+albumName;
      oReq.send(para);
	 
	 // alert(oReq.responseText);
	  
	  LoadAlbumList();
	  
	  HideAddAlbum();
	}	
}

function ShowAddAlbum()
{
	var addAlbumDiv=document.getElementById('addAlbumDiv');
	addAlbumDiv.style.display="block";
}

function HideAddAlbum()
{
	var addAlbumDiv=document.getElementById('addAlbumDiv');
	addAlbumDiv.style.display="none";
}

//上传图片
function UploadPhoto()
{
	var txtAlbumId=document.getElementById('txtAlbumId');
	var txtAlbumList=document.getElementById('txtAlbumList');
	//alert(txtAlbumList.value);
	txtAlbumId.value=txtAlbumList.value;
	
	var uploadForm=document.getElementById('uploadForm');
	uploadForm.submit();
	//alert(txtAlbumId.value);
		
}

</script>
</head>
<body onload="LoadAlbumList()" >
<div style=" position:relative">
上传到相册
<select id="txtAlbumList">
</select>
<input type="button" onclick="ShowAddAlbum()" value="新建相册" />
<a href="album_view.htm">查看相册</a>
<div id="addAlbumDiv" style="width:400px; display:none; position:absolute; z-index:101; left:150px; top:50px; background-color:#ccc;padding:10px;">
<div>创建新相册</div>
<div>相册名称:<input id="txtAlbumName" /><br /><br />
<input type="button" value="确定" onclick="AddAlbum()"/>
<input type="button" value="取消" onclick="HideAddAlbum()"/>
</div>
</div>

<div>上传照片：
<form id="uploadForm" action="upload_photo.php" method="post" enctype="multipart/form-data">
<input id="txtPhoto"  name="txtPhoto" type="file"  />
<input id="txtAlbumId" name="txtAlbumId" type="hidden" />
<input id="btnUpload" type="button" value="上传"  onclick="UploadPhoto()" />
</form>
</div>
</div>
</body>
</html>
